package com.qf.smsplatform.search.mq;

import com.qf.smsplatform.common.constants.RabbitMQConstants;
import com.qf.smsplatform.common.index.StandardReport;
import com.qf.smsplatform.common.index.StandardSubmit;
import com.qf.smsplatform.search.service.SearchService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Slf4j
public class SmsUpdateLogStreamListener {

    @Autowired
    private SearchService searchService;

    @StreamListener(RabbitMQConstants.TOPIC_UPDATE_SMS_REPORT)
    public void listen(StandardReport report,
                       @Header(name = AmqpHeaders.CHANNEL)Channel channel,
                       @Header(name = AmqpHeaders.DELIVERY_TAG)Long deliveryTag) throws IOException {
        log.info("【搜索模块】 修改submit日志信息. report = {}",report);
        // 调用searchService修改日志信息
        searchService.update(report);
        // 手动ack
        channel.basicAck(deliveryTag,false);
    }

}
